package cn.minimelon.cushaw.impl;

import cn.minimelon.bittermelon.bean.LoginUser;
import cn.minimelon.bittermelon.utils.Melon;
import cn.minimelon.cushaw.dao.SysAreaDao;
import cn.minimelon.cushaw.entity.SysArea;
import cn.minimelon.cushaw.service.SysAreaService;
import org.beetl.sql.ext.solon.Db;
import org.noear.solon.extend.aspect.annotation.Service;

import java.util.List;

@Service
public class SysAreaServiceImpl implements SysAreaService {
    @Db
    SysAreaDao areaDao;

    @Override
    public List<SysArea> selectAll(LoginUser user) {
        List<SysArea> areaList = areaDao.all();
        if (user != null) {
            SysArea platform = new SysArea();
            platform.setUid(1000L);
            platform.setCode("platform");
            platform.setName("基础平台");
            areaList.add(0, platform);
        }
        return areaList;
    }

    @Override
    public void save(SysArea area, LoginUser user) {
        Melon.setInsertInfo(area, user);
        areaDao.insert(area);
    }

    @Override
    public Integer update(SysArea area, LoginUser user) {
        Melon.setUpdateInfo(area, user);
        return areaDao.updateById(area);
    }
}
